package com.cincc.taofangwang.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.cincc.taofangwang.R;
import com.cincc.taofangwang.common.callback.OnClickCallBack;
import com.cincc.taofangwang.common.callback.TaskCallBack;
import com.cincc.taofangwang.model.TaskModel;

import java.util.List;

public class TaskNameAdapter extends RecyclerView.Adapter<TaskNameAdapter.MyViewHolder> {

    private Context context;
    private List<TaskModel> list;

    public TaskNameAdapter(Context context, List<TaskModel> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_task_name, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        TaskModel model = list.get(position);
        holder.nameText.setText(model.taskName);
        holder.itemView.setOnClickListener(v -> onClickBallBack.callback(model.taskId));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        TextView nameText;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            nameText = itemView.findViewById(R.id.task_name_tv);
        }
    }

    public TaskCallBack onClickBallBack;

    public void setCallBack(TaskCallBack callBack) {
        this.onClickBallBack = callBack;
    }
}
